package com.example.demo.framework.conf;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import com.example.demo.framework.AdminInterceptor;
import com.example.demo.framework.LoginInterceptor;

@Configuration
public class CustomWebMvcConfiguration extends WebMvcConfigurationSupport {

	@Autowired
	private LoginInterceptor loginInterceptor;

	@Autowired
	private AdminInterceptor adminInterceptor;

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(loginInterceptor).addPathPatterns("/user/**").addPathPatterns("/admin/**")
				.addPathPatterns("/notice/**").addPathPatterns("/fund/**");
		registry.addInterceptor(adminInterceptor).addPathPatterns("/admin/**");
		super.addInterceptors(registry);
	}

	@Override
	protected void addCorsMappings(CorsRegistry registry) {
		 registry.addMapping("/**")
	        .allowedOrigins("*")
	        .allowedMethods("GET", "POST", "PUT", "OPTIONS", "DELETE", "PATCH")
	          .allowCredentials(true).maxAge(3600);
		super.addCorsMappings(registry);
	}
	


}
